home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 026-050 / scopedisk41 / snipit12 / patch.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  2KB  |  92 lines

  1. /* "Patch" fix SnipIt to use a different keymap */
  2. /* 9/1/88 - Scott Evernden */
  3.  
  4. #include <stdio.h>
  5. #include <ctype.h>
  6.  
  7. FILE *infile, *datafile;
  8.  
  9. /* original keycode table starts like this... */
  10. unsigned char match[] = {
  11.     0x40, 0x81, 0xAA, 0x83, 0x84, 0x85, 0x87, 0x2A,
  12.     0x89, 0x8A, 0x88, 0x8C, 0x38, 0x0B, 0x39, 0x3A,
  13.     0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0
  14. };
  15.  
  16. main()
  17. {
  18.     long pos, ftell();
  19.     unsigned char *mp;
  20.     int ch, i;
  21.  
  22.     /* gonna write into this file */
  23.     infile = fopen("SnipIt", "r+");
  24.     if (!infile) {
  25.         puts("Can't open \"SnipIt\"");
  26.         exit(0);
  27.     }
  28.  
  29.     /8 need to read this one */
  30.     datafile = fopen("SnipIt.keys", "r");
  31.     if (!datafile) {
  32.         puts("Can't open \"SnipIt.keys\"");
  33.         exit(0);
  34.     }
  35.  
  36.     /* locate original table */
  37.     mp = match;
  38.     while (*mp && (ch = fgetc(infile)) != EOF) {
  39.         if (ch != *mp)
  40.             mp = match;
  41.         else if (mp++ == match)
  42.             pos = ftell(infile) - 1;
  43.     }
  44.  
  45.     if (ch == EOF) {
  46.         puts("Are you sure this is an original copy of \"SnipIt\"?");
  47.         fclose(infile);
  48.         fclose(datafile);
  49.         exit(0);
  50.     }
  51.  
  52.     fputs("Patching keytable...", stdout);
  53.  
  54.     fseek(infile, pos, 0L);
  55.  
  56.     for (i = 32; i < 127; i++)
  57.         fputc(innum() & 0xFF, infile);
  58.  
  59.     fclose(infile);
  60.     fclose(datafile);
  61.     puts("done");
  62. }
  63.  
  64.  
  65. innum()
  66. {
  67.     int result;
  68.     int ch;
  69.  
  70.     do {
  71.         ch = fgetc(datafile);
  72.     } while (!isxdigit(ch));
  73.  
  74.     if (ch == EOF)
  75.         return 0;
  76.  
  77.     result = 0;
  78.     do {
  79.         ch -= '0';
  80.         if (9 < ch)
  81.             ch -= 7;
  82.         if (15 < ch)
  83.             ch -= 32;
  84.         result = result * 16 + ch;
  85.         ch = fgetc(datafile);
  86.     } while (isxdigit(ch));
  87.  
  88.     return result;
  89. }
  90.  
  91.  
  92.